﻿@using Webdiyer.WebControls.Mvc
@model MvcWeb.ViewModels.Manager.ManagerSearchModel
@{
    ViewBag.Title = "资产查询";
    var brandInfoDict = (Dictionary<int, string>)ViewData["brandInfoDict"];
}
@if (false)
{
        <script src="../../Scripts/jquery-1.5.1-vsdoc.js" type="text/javascript"></script>
}

<div style="padding: 5px 10px;">
    <span class="btn_green">资产查询</span>
</div>

<div style="padding: 0px 10px; margin-bottom: 5px;">
    <table id="searchbox" class="tb" width="98%" style="text-align: center;">
      @using (Html.BeginForm())
      {
         <tr>
            <td >资产名称</td>
            <td >
                 @Html.TextBoxFor(m => m.conditionModel.AssetName)
            </td>            

            <td >资产条形码</td>
            <td>
                     @Html.TextBoxFor(m => m.conditionModel.AssetBarcode)
            </td>

            </tr>
            
         <tr>

            <td >资产标签</td>
            <td>
                     @Html.TextBoxFor(m => m.conditionModel.AssetLabel)
            </td> 

            

            <td >购买起始时间</td>
            <td >
                    @Html.TextBoxFor(m => m.conditionModel.AssetStartBuyTime)
                    @Html.TextBoxFor(m => m.conditionModel.AssetEndBuyTime)
            </td>
            </tr>
         

            <tr>
            <td >资产状态</td>
            <td>
                     @Html.DropDownListFor(m => m.conditionModel.AssetStatus, new SelectList((Dictionary<int, string>)ViewData["statusDict"], "key", "value"), "请选择类型")
            </td>
        

            <td >资产分类</td>
            <td>
                    @Html.DropDownListFor(m => m.conditionModel.AssetCID, new SelectList((Dictionary<int, string>)ViewData["categoryCID"], "key", "value"), "请选择类型")
            </td>

            </tr>
         

            <tr>
             
            <td >资产品牌</td>
            <td>
                    @Html.DropDownListFor(m => m.conditionModel.AssetBrand, new SelectList((Dictionary<int, string>)ViewData["brandDict"], "key", "value"), "请选择类型")
            </td>             
        
            <td >资产供应商</td>
            <td>
                    @Html.DropDownListFor(m => m.conditionModel.AssetSupply, new SelectList((Dictionary<int, string>)ViewData["supplyDict"], "key", "value"), "请选择类型")
            </td>
            </tr>

            <tr>
            <td >使用部门</td>
            <td>
                    @Html.DropDownListFor(m => m.conditionModel.AssetDepartID, new SelectList((Dictionary<int, string>)ViewData["AssetDepartIDDict"], "key", "value"), "请选择类型")
            </td>            
         
            <td >保管人</td>
            <td>
                    @Html.DropDownListFor(m => m.conditionModel.AssetCustodyMemberID, new SelectList((Dictionary<Guid, string>)ViewData["AssetCustodyMemberIDDict"], "key", "value"), "请选择类型")
            </td>
         </tr>
          
          <tr>
          <td >存放地点</td>
            <td  colspan="3" >
                    @Html.TextBoxFor(m => m.conditionModel.AssetCustodyAddress, new { @style = "width:98%;" })
            </td> 
          </tr>
         
         
         <tr>
             <td colspan="4">
                <input type="submit" id="search" class="btn_green" value="查询"  />
             </td>
           </tr>  
         
      }
  
    </table>
</div>



<div style="padding: 0px 10px;">
    <table class="tb" width="98%" style="text-align: center;">
        <tr>
            <th style="width: 20px;"></th>
            <th valign="top">序号</th>
            <th>名称</th>
            <th>标签</th>
            <th>状态</th>
            <th>供应商</th>
            <th>供应商联系人</th>
            <th>保修时间</th>
            <th>保管人</th>
            <th>使用人</th>
            <th>所在部门</th>
        </tr>
        @foreach (var m in Model.managerModelList)
        {
            <tr>
                <td><input type="checkbox" name="aid" value="@m.AssetID" /></td>
                <td>@m.AssetID</td>
                <td>@m.AssetName</td>
                <td>@m.AssetLabel</td>
                <td>@( ((Dictionary<int, string>)ViewData["statusDict"])[(m.AssetStatus ?? -1)]) </td>
                <td>@( ((Dictionary<int, string>)ViewData["supplyDict"])[(m.AssetSupply ?? -1)]) </td>
                <td>@brandInfoDict[(m.AssetSupply ?? -1)] </td>
                <td>@m.AssetWarrantLastTime</td>
                <td>@( ((Dictionary<Guid, string>)ViewData["AssetCustodyMemberIDDict"])[(m.AssetCustodyMemberID ?? new Guid())])</td>
                <td>@( ((Dictionary<Guid, string>)ViewData["AssetCustodyMemberIDDict"])[(m.AssetUsedMemberID ?? new Guid())])</td>
                <td>@( ((Dictionary<int, string>)ViewData["AssetDepartIDDict"])[(m.AssetDepartID ?? -1)])</td>
                
            </tr>
        }
        <tr>
            <td><input type="checkbox" /></td>


            <td colspan="10" style="text-align: left;"> 

            <div style="float: right;">
                    @Html.Pager(Model.managerModelList)
                </div>

                    修改状态:@Html.DropDownListFor(m => m.assetStatus, new SelectList((Dictionary<int, string>)ViewData["statusDict"], "key", "value"), "请选择类型")
                    修改等级:@Html.DropDownListFor(m => m.assetLevel, new SelectList((Dictionary<int, string>)ViewData["assetLevelDict"], "key", "value"), "请选择类型")
                    <input type="button" value="批量修改" class="btn_green" onclick="batchEdit();" />
                    <input type="button" value="资产合并" class="btn_green" onclick="batchMerger();" />
                 
            </td>
        </tr>
    </table>
</div>

<script type="text/javascript">
    $(function () {
        $("#conditionModel_AssetStartBuyTime").ligerDateEditor({ initValue: $("#conditionModel_AssetStartBuyTime").val() });
        $("#conditionModel_AssetEndBuyTime").ligerDateEditor({ initValue: $("#conditionModel_AssetEndBuyTime").val() });



        $("#assetStatus").change(function () {
            var operValue = $(this).val();
            var text = $("#assetStatus option:selected").text();

            var arr = [];
            $("input[name='aid']:checked").each(function () {
                arr.push($(this).val());
            });


            $.get('/ManagerSearch/setStatus/' + arr.join(',') + "?oper=" + operValue + '&t=' + Math.random(), function (data) {
                alert("设置成功");
            });
        });


        $("#assetLevel").change(function () {
            var operValue = $(this).val();
            var text = $("#assetLevel option:selected").text();

            var arr = [];
            $("input[name='aid']:checked").each(function () {
                arr.push($(this).val());
            });

            $.get('/ManagerSearch/setLevel/' + arr.join(',') + "?oper=" + operValue + '&t=' + Math.random(), function (data) {
                alert("设置成功");
            });
        });


    });


    function batchEdit() {
            var arr = [];
            $("input[name='aid']:checked").each(function () {
                arr.push($(this).val());
            });

            if (arr.join(',') == "") {
                alert("请选择要操作的资产");
                return;
            }
            var url = '/ManagerSearch/BatchEdit/' + arr.join(',')+ '?t=' + Math.random();
            window.location = url;
        }


        function batchMerger() {
            var arr = [];
            $("input[name='aid']:checked").each(function () {
                arr.push($(this).val());
            });

            if (arr.join(',') == "") {
                alert("请选择要操作的资产");
                return;
            }
            var url = '/ManagerSearch/batchMerger/' + arr.join(',') + '?t=' + Math.random();
            window.location = url;
        }
</script>
